<?php
	namespace Admin\Model;
	use Think\Model;
	class CategoryModel extends Model{

		public function getAll($pid,$limit){
			
			$list=$this->where("pid=$pid")->limit($limit)->select();
			foreach ($list as  &$value) {
				$value['ppid']=$value['pid'];
				$value['path']=count(explode(',',trim($value['path'],',')));	
			}
			return $list;

		}
		public function likeGet($where,$limit){
			
			$list=$this->where($where)->limit($limit)->select();
			foreach ($list as  &$value) {
				$value['ppid']=$value['pid'];
				$value['path']=count(explode(',',trim($value['path'],',')));
				
			}
		
			return $list;
		}

		public function change($status,$id){
			$data['status']=!$status;
			$this->where("id=$id")->save($data);
		}

		public function delFind($id){
			$list=$this->where("pid=$id")->select();
			return $list;
		}
		public function del($id){
			$res=$this->where("id=$id")->delete();
			return $res;
		}

		public function addFind($pid){
			$list=$this->where("id=$pid")->select();
			if (empty($list)) {
				error('错误');
				return false;
			}
			$str='';
			$str=$list[0]['path'].$pid.',';
			return $data['path']=$str;
		}
		public function add1($data){
			$res=$this->data($data)->add();
			return $res;
		}
	}